/* Guile-GCC
   Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>

   This file is part of Guile-GCC.

   Guile-GCC is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   Guile-GCC is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with Guile-GCC.  If not, see <http://www.gnu.org/licenses/>.  */

#include <gcc-plugin.h>

#include <plugin.h>
#include <cpplib.h>
#include <tree.h>

#include <gimple.h>

#include <ggcc-utils.h>

#define MAKE_GIMPLE_ACCESSOR(func, to_scm)				\
  SCM_DEFINE (ggcc_gimple_ ## func, "%gimple-" STRINGIFY (func),	\
	      1, 0, 0,							\
	      (SCM pointer),						\
	      "Return the " STRINGIFY (func) " of @var{pointer}.")	\
  {									\
    return to_scm (gimple_ ## func ((gimple) SCM_POINTER_VALUE (pointer))); \
  }

MAKE_GIMPLE_ACCESSOR (code, scm_from_int)
MAKE_GIMPLE_ACCESSOR (location, scm_from_long)
MAKE_GIMPLE_ACCESSOR (call_fndecl, ggcc_from_pointer)
MAKE_GIMPLE_ACCESSOR (call_lhs, ggcc_from_pointer)
MAKE_GIMPLE_ACCESSOR (bb, ggcc_from_pointer)


/* The initialization routine for the (gcc gimple) module.  It is called
   directly from Scheme.  */

void
ggcc_init_gimple (void)
{
#include "gimple.x"

#define DEFGSCODE(symbol, name, gss_symbol)			\
  scm_define (scm_from_latin1_symbol (STRINGIFY (symbol)),	\
	      scm_from_int (symbol));
#include "gimple.def"
#undef DEFGSCODE
}
